﻿
    using Maticsoft.BLL;
    using Maticsoft.DBUtility;
    using Maticsoft.Model;

    using System;
    using System.Data;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Utils;
    using Wuqi.Webdiyer;

    public partial class partner : FBasePage
    {
        private Maticsoft.BLL.Partner b_partner = new Maticsoft.BLL.Partner();

        private Maticsoft.Model.Partner m_partner = null;
        public string strAdress = "";
        public string strHomePage = "";
        public string strImg = "";
        public string strImg1 = "";
        public string strImg2 = "";
        public string strJoinNumber = "";
        public string strOther = "";
        public string strPhone = "";
        public string strSaveNumber = "";
        public string strTeamCount = "";
        public string strTitile = "";

        private void initPage()
        {
            string str = "";
            if ((base.Request["id"] != null) && (base.Request["id"].ToString() != ""))
            {
                str = base.Request["id"].ToString();
                if (!Utility.IsNum(str))
                {
                    this.SetError("参数错误！");
                }
                else
                {
                    this.m_partner = this.b_partner.GetModel(int.Parse(str));
                    this.strTitile = this.m_partner.Title;
                    this.strOther = this.m_partner.Other;
                    this.strPhone = this.m_partner.Phone;
                    this.strAdress = this.m_partner.Address;
                    this.strHomePage = this.m_partner.Homepage;
                    this.strImg = this.m_partner.Image;
                    string open = this.m_partner.Open;
                    StringBuilder builder = new StringBuilder();
                    StringBuilder builder2 = new StringBuilder();
                    if (this.m_partner.Image1 != "")
                    {
                        this.strImg1 = this.m_partner.Image1;
                        builder.Append("<li><img src=\"" + this.strImg1 + "\"/></li>");
                        builder2.Append("<a ref=\"2\" >2</a>");
                    }
                    if (this.m_partner.Image2 != "")
                    {
                        this.strImg2 = this.m_partner.Image2;
                        builder.Append("<li><img src=\"" + this.strImg2 + "\"/></li>");
                        builder2.Append("<a ref=\"3\" >3</a>");
                    }
                    this.ltIndex.Text = builder2.ToString();
                    this.ltImg.Text = builder.ToString();
                    Maticsoft.BLL.Team team = new Maticsoft.BLL.Team();
                    this.strTeamCount = team.GetCount("count(*)", "Partner_id =" + str).ToString();
                    this.strJoinNumber = team.GetCount("sum(Now_number)", "Partner_id =" + str).ToString();
                    float num = 0f;
                    DataSet list = team.GetList(" Partner_id=" + str);
                    if (((list != null) && (list.Tables.Count > 0)) && (list.Tables[0].Rows.Count > 0))
                    {
                        for (int i = 0; i < list.Tables[0].Rows.Count; i++)
                        {
                            DataRow row = list.Tables[0].Rows[i];
                            float num3 = float.Parse(row["Market_price"].ToString());
                            float num4 = float.Parse(row["Team_price"].ToString());
                            float num5 = num3 - num4;
                            Maticsoft.BLL.Order order = new Maticsoft.BLL.Order();
                            int num6 = int.Parse(order.GetCount("sum(Quantity)", "Team_id=" + row["id"].ToString()));
                            num += num5 * num6;
                        }
                    }
                    this.strSaveNumber = num.ToString();
                    this.initPro(int.Parse(str));
                }
            }
        }

        private void initPro(int PartnerID)
        {
            int num;
            string str = "";
            DataSet list = new Maticsoft.BLL.System().GetList("");
            if (((list != null) && (list.Tables.Count > 0)) && (list.Tables[0].Rows.Count > 0))
            {
                str = list.Tables[0].Rows[0]["Currency"].ToString();
            }
            StringBuilder builder = new StringBuilder();
            Maticsoft.BLL.Team team = new Maticsoft.BLL.Team();
            string where = " Partner_id=" + PartnerID;
            DataSet set2 = DbHelperSQL.Page(4, this.pager.CurrentPageIndex, "Team", where, "  Begin_time desc", "*", out num);
            this.m_partner = this.b_partner.GetModel(PartnerID);
            if (this.m_partner != null)
            {
                this.strTitile = this.m_partner.Title;
                this.strOther = this.m_partner.Other;
                this.strPhone = this.m_partner.Phone;
                this.strAdress = this.m_partner.Address;
                this.strHomePage = this.m_partner.Homepage;
                this.strImg = this.m_partner.Image;
            }
            if (((set2 != null) && (set2.Tables.Count > 0)) && (set2.Tables[0].Rows.Count > 0))
            {
                for (int i = 0; i < set2.Tables[0].Rows.Count; i++)
                {
                    string str3 = set2.Tables[0].Rows[i]["ID"].ToString();
                    string str4 = set2.Tables[0].Rows[i]["Title"].ToString();
                    string s = set2.Tables[0].Rows[i]["Begin_time"].ToString();
                    string str6 = set2.Tables[0].Rows[i]["Mobile"].ToString();
                    string str7 = set2.Tables[0].Rows[i]["Image"].ToString();
                    string str8 = set2.Tables[0].Rows[i]["Now_number"].ToString();
                    string str9 = set2.Tables[0].Rows[i]["Team_price"].ToString();
                    string str10 = set2.Tables[0].Rows[i]["Market_price"].ToString();
                    string discount = WebSiteHelper.GetDiscount(Helper.GetDecimal(str10, 0M), Helper.GetDecimal(str9, 0M));
                    builder.Append("<li>");
                    builder.Append("<p class=\"time\">" + DateTime.Parse(s).ToString("yyyy-MM-dd") + "</p>");
                    builder.Append("<h4><a href=\"/team.aspx?id=" + str3 + "\" title=\"" + str4 + "\" target=\"_blank\">" + str4 + "</a></h4>");
                    builder.Append("<div class=\"pic\">");
                    builder.Append("<div></div>");
                    builder.Append("<a href=\"/team.aspx?id=" + str3 + "\" title=\"" + str4 + "\" target=\"_blank\"><img alt=\"" + str4 + "\" src=\"" + str7 + "\" width=\"200\" height=\"121\"></a>");
                    builder.Append("</div>");
                    builder.Append("<div class=\"info\"><p class=\"total\"><strong class=\"count\">" + str8 + "</strong>人购买</p><p class=\"price\">原价：<strong class=\"old\"><span class=\"money\">" + str + "</span>" + str10 + "</strong><br />折扣：<strong class=\"discount\">" + discount + "</strong><br />现价：<strong><span class=\"money\">" + str + "</span>" + str9 + "</strong><br />节省：<strong><span class=\"money\">" + str + "</span>" + Convert.ToString((float)(float.Parse(str10) - float.Parse(str9))) + "</strong><br /></p></div>");
                    builder.Append("</li>");
                }
            }
            this.ltPro.Text = builder.ToString();
            this.pager.RecordCount = num;
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!this.Page.IsPostBack)
            {
                this.initPage();
            }
        }

        protected void pager_PageChanged(object sender, EventArgs e)
        {
            if ((base.Request["id"] != null) && (base.Request["id"].ToString() != ""))
            {
                string s = base.Request["id"].ToString();
                this.initPro(int.Parse(s));
            }
        }
    }


